package com.audaque.springboot.foshanupload.redis.service.impl;

import com.audaque.springboot.foshanupload.redis.anno.RedissonLockAnno;
import com.audaque.springboot.foshanupload.redis.service.RedissonLockAnnoService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zgb
 * @desc ...
 * @date 2021-12-26 18:36:42
 */
@Slf4j
@Service
public class RedissonLockAnnoServiceImpl implements RedissonLockAnnoService {

    @Autowired
    RedissonLockAnnoService redissonLockAnnoService;


    @RedissonLockAnno(unlockYn = false, waitTime = 0, leaseTime = 5, lockIndexs = {0}, msg = "获取token过于频繁")
    public void add(String key) throws Exception {

    }

    public Boolean addResult(String key) {
        Boolean result = true;
        try {
            redissonLockAnnoService.add(key);
        } catch (Exception e) {
            //并发异常或获取不到令牌
            result = false;
        }
        return result;
    }
}
